package com.example.myapplication.ui.self;

import androidx.databinding.DataBindingUtil;
import androidx.lifecycle.ViewModelProvider;
import androidx.lifecycle.ViewModelProviders;

import android.content.Intent;
import android.os.Bundle;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.myapplication.R;
import com.example.myapplication.databinding.SelfFragmentBinding;
import com.example.myapplication.ui.login.MainActivity;
import com.example.myapplication.ui.modify.ModifyActivity;
import com.example.myapplication.ui.register.RegisterViewModel;

public class SelfFragment extends Fragment {

    private SelfViewModel mViewModel;
    private SelfFragmentBinding binding;

    public static SelfFragment newInstance() {
        return new SelfFragment();
    }

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container,
                             @Nullable Bundle savedInstanceState) {


        mViewModel = new ViewModelProvider(this).get(SelfViewModel.class);
        binding = DataBindingUtil.inflate(inflater, R.layout.self_fragment, container, false);
        binding.setData(mViewModel);

        /**
         * 跳转到修改页面
         */
        binding.m.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(getContext(), ModifyActivity.class);
                startActivity(intent);
            }
        });
        binding.toolbar3.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                getActivity().finish();
            }
        });
        return binding.getRoot();
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        mViewModel = ViewModelProviders.of(this).get(SelfViewModel.class);
        // TODO: Use the ViewModel
    }

}